/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.wicket;

import org.apache.wicket.Request;
import org.apache.wicket.protocol.http.WebSession;
import Entities.*;
import DataLayer.*;


public final class SignInSession extends WebSession
{
    private int userId;
    private String userName;

    protected SignInSession(Request request)
    {
        super(request);
    }

    public final boolean authenticate(final String username, final String password)
    {
        if (userName == null)
        {
             DataRepository repository = new DataRepository();
             User dtoUser =new User();
             dtoUser=repository.getUserByLogin(username);
            // Trivial password "db"
            if (dtoUser != null && dtoUser.Password.equalsIgnoreCase(password))
            {
                userId = dtoUser.Id;
                userName = dtoUser.Name;
            }
        }

        return userName != null;
    }

    public boolean isSignedIn()
    {
        return userName != null;
    }

    public int getUserId()
    {
        return userId;
    }
    
    public String getUserName()
    {
        return userName;
    }

    public void setUserName(final String user)
    {
        this.userName = user;
    }
}
